﻿<?php
    $arrayid=$_POST['arrayid'];
    $id=$_GET['id'];
    $user=$_GET['username'];

 	session_start();
   //得到当前用户
    session_start();

	if(!isset($_SESSION['id'])){
		header('Location:login.php');
	}
	$username=$_SESSION['username'];
	$sessionid=session_id();
   	$connect=mysql_connect("localhost","root","");
   	mysql_select_db("shenji",$connect);
   	mysql_query("set names utf8");
	if(isset($arrayid[0])){
		 foreach ($arrayid as $id){
           $sql="delete from user where id=$id and username!='".$username."'";
		   mysql_query($sql);
	   	   $sql2="select data from sessions where sid=$id and data!='".$sessionid."'";
		   $result2=mysql_query($sql2);
		   while($row2=mysql_fetch_assoc($result2)){;
	   
		   //$username1=$row2['username'];
		   $data=$row2['data'];
		}
	   
		   $data1="/var/lib/php/session/sess_"."$data";
		   unlink($data1);
		   $sql3="delete from sessions where username=$user and data!='".$sessionid."'";
		   mysql_query($sql3);
	    }

     }
   if(isset($id)){
	   $sql="delete from user where id=$id and username!='".$username."'";
	   mysql_query($sql);

	   //session_unset('username');
	   $sql2="select * from sessions where username='$user' and data!='".$sessionid."'";
	   $result2=mysql_query($sql2);
	   while($row2=mysql_fetch_assoc($result2)){;
	   
	   //$username1=$row2['username'];
	   $data=$row2['data'];
	}
	   $data1="/var/lib/php/session/sess_"."$data";
	   unlink($data1);
	   $sql3="delete from sessions where username='$user' and data!='".$sessionid."'";
	   mysql_query($sql3);
   }
    
	echo "<script>location.href='select_user.php'</script>";
	
	
	
	
	
?>